package com.cry.app.core.utils;

import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.lang.reflect.Modifier;
import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;

public class BeanCompare {

	private static HashSet<Method> getGetters(Class clazz, String[] excludeList) {
		HashSet<Method> m = new HashSet<Method>();

		List<String> exclude = (List<String>) Arrays.asList(excludeList);
        
        for(Method method : clazz.getMethods()) {
            if(method.getName().startsWith("get") && !exclude.contains(method.getName()) && (Modifier.PUBLIC & method.getModifiers()) == Modifier.PUBLIC) {
            	System.out.println(method.getName() + " - " + method.getModifiers() + " -- " +method.getAnnotations());
            	m.add(method);
            }
        }
        return m;
        
	}

	public static boolean compare(Object obj1, Object obj2, String... excludeList) throws IllegalArgumentException, IllegalAccessException, InvocationTargetException {

		HashSet<Method> getters = getGetters(obj1.getClass(), excludeList);

		for(Method getter : getters) {
			Object value1 = getter.invoke(obj1);
			Object value2 = getter.invoke(obj2);
			
			System.out.println(getter.getName() + ": " + value1 + " == " + value2);
			
		}
		
		return false;
	}
	
}
